using ASP;
using HoWave.Common;
using HoWave.Data.Bll;
using HoWave.Web;
using HoWave.Web.Shop.Member;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
public class Member_PromotionManage_ProductPromotion : Member, IRequiresSessionState
{
	private string linkHead = "";
	public string m_flag = "1";
	public string EnableSingleSell = "";
	public string ProType = "4";
	private string tabMenu = "";
	protected ScriptManager ScriptManager1;
	protected Literal ltrTitle;
	protected Label lblSale;
	protected Label lblStock;
	protected TextBox txtProductName;
	protected Button SeachBut;
	protected GridView gvManage;
	protected Literal ltrPagePanel;
	protected Button btnMoreStopSale;
	protected Button btnMoreOnSale;
	protected Button btnMoreDelete;
	protected Literal ltrTishi;
	protected PlaceHolder phManage;
	public string TabMenu
	{
		get
		{
			if (base.Request.QueryString["TabMenu"] != null)
			{
				this.tabMenu = base.Request.QueryString["TabMenu"].Trim();
			}
			else
			{
				this.tabMenu = "tabSale";
			}
			return this.tabMenu;
		}
		set
		{
			this.tabMenu = value;
		}
	}
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!base.IsPostBack)
		{
			if (!base.OwnerPromotionPower(base.user.UserID))
			{
				base.WriteRightErrMsg();
			}
			this.ShowPanelDisplay(this.TabMenu);
			this.BindProductScore();
		}
	}
	protected void ShowPanelDisplay(string DisplayName)
	{
		this.btnMoreDelete.Visible = false;
		this.btnMoreStopSale.Visible = false;
		this.btnMoreOnSale.Visible = false;
		if (DisplayName != null)
		{
			if (!(DisplayName == "tabSale"))
			{
				if (DisplayName == "tabStock")
				{
					this.m_flag = "0";
					this.btnMoreDelete.Visible = true;
					this.btnMoreOnSale.Visible = true;
					this.ltrTishi.Text = "提示：这里的删除是把商品放到回收站中。";
				}
			}
			else
			{
				this.m_flag = "1";
				this.btnMoreStopSale.Visible = true;
			}
		}
		Cookie.SaveCookie("Contacter_m_flag", this.m_flag, 0, "");
	}
	protected void BindProductScore()
	{
		CurrPageLinks currPageLinks = new CurrPageLinks();
		string query = this.GetQuery();
		string queryByOrder = this.GetQueryByOrder();
		int num = this.gvManage.PageIndex;
		if (Fetch.Get("pageindex") != null)
		{
			num = Convert.ToInt32(Fetch.GetID("pageindex").ToString());
			if (num == 0)
			{
				num = 1;
			}
		}
		string text = string.Concat(new object[]
		{
			" from HLShop_Product where IsDeleted=0 and EnableSale=",
			this.m_flag,
			this.EnableSingleSell,
			" and ProductType=",
			this.ProType,
			" and SalerID=",
			base.user.UserID,
			" "
		});
		int pageSize = this.gvManage.PageSize;
		ClientByPage clientByPage = new ClientByPage();
		int listCount = clientByPage.GetListCount("select count(*)" + text + query);
		string url = "PromotionManage/ProductPromotion.aspx?TabMenu=" + this.TabMenu + this.linkHead + "&pageindex";
		int startIndex = (num - 1) * pageSize + 1;
		int endIndex = num * pageSize;
		string str = "ROW_NUMBER() OVER (" + queryByOrder + ") as row,ProductID,ProductType,ProductSmallImageUrl,ProductName,Stocks,AlarmNum,PUnit,CurrentPrice,StandPrice,BeginDate,EndDate,IsElite,EnableSale,PresentExp ";
		string strSQL = "select " + str + text + query;
		DataTable listPage = clientByPage.GetListPage(strSQL, "row", startIndex, endIndex);
		this.gvManage.DataSource = listPage;
		this.gvManage.DataBind();
		if (listPage.Rows.Count > 0)
		{
			this.ltrPagePanel.Text = currPageLinks.CurrPageLink(num, pageSize, listCount, "条记录", url);
		}
		if (this.m_flag == "1")
		{
			for (int i = 0; i < this.gvManage.Rows.Count; i++)
			{
				LinkButton linkButton = (LinkButton)this.gvManage.Rows[i].FindControl("lbtnStopSale");
				LinkButton linkButton2 = (LinkButton)this.gvManage.Rows[i].FindControl("lbtnOnSale");
				LinkButton linkButton3 = (LinkButton)this.gvManage.Rows[i].FindControl("lbtnDelete");
				linkButton.Visible = true;
				linkButton2.Visible = false;
				linkButton3.Visible = false;
			}
		}
		else
		{
			if (this.m_flag == "0")
			{
				for (int i = 0; i < this.gvManage.Rows.Count; i++)
				{
					LinkButton linkButton = (LinkButton)this.gvManage.Rows[i].FindControl("lbtnStopSale");
					LinkButton linkButton2 = (LinkButton)this.gvManage.Rows[i].FindControl("lbtnOnSale");
					LinkButton linkButton3 = (LinkButton)this.gvManage.Rows[i].FindControl("lbtnDelete");
					linkButton.Visible = false;
					linkButton2.Visible = true;
					linkButton3.Visible = true;
				}
			}
		}
	}
	protected string GetQuery()
	{
		string text = "";
		string text2 = Fetch.Get("ProductName");
		if (!string.IsNullOrEmpty(text2))
		{
			if (text2 != this.txtProductName.Text.Trim())
			{
				text2 = this.txtProductName.Text.Trim();
			}
			this.txtProductName.Text = text2;
		}
		else
		{
			text2 = this.txtProductName.Text;
		}
		if (!string.IsNullOrEmpty(text2))
		{
			text = text + " and ProductName like '%" + text2 + "%'";
			this.linkHead = this.linkHead + "&ProductName=" + text2;
		}
		return text;
	}
	private string GetQueryByOrder()
	{
		return "order by ProductID desc";
	}
	protected void gvManage_RowDataBound(object sender, GridViewRowEventArgs e)
	{
		if (e.Row.RowType == DataControlRowType.DataRow)
		{
			e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#E7EDFE'");
			e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
		}
	}
	protected void gvManage_PageIndexChanging(object sender, GridViewPageEventArgs e)
	{
		this.gvManage.PageIndex = e.NewPageIndex;
		this.BindProductScore();
	}
	protected void Button_Command(object sender, CommandEventArgs e)
	{
		string comeUrl = "ProductPromotion.aspx?TabMenu=" + this.TabMenu + this.linkHead + "&pageindex";
		string commandName = e.CommandName;
		if (commandName == "MoreDelete")
		{
			string text = Text.CheckNumList(Fetch.GetOrPost("SelectId"));
			if (text != "")
			{
				int num = 0;
				string[] array = text.Split(new char[]
				{
					','
				});
				for (int i = 0; i < array.Length; i++)
				{
					num = this.ProdcutDelete(array[i]);
				}
				if (num > 0)
				{
					this.WriteErrMsg("", "批量信息删除成功！", comeUrl);
				}
			}
			else
			{
				this.WriteErrMsg("", "请选择您要删除的信息", "");
			}
		}
		else
		{
			if (commandName == "MoreStopSale")
			{
				string text = Text.CheckNumList(Fetch.GetOrPost("SelectId"));
				if (text != "")
				{
					int num = 0;
					string[] array = text.Split(new char[]
					{
						','
					});
					for (int i = 0; i < array.Length; i++)
					{
						num = this.ProdcutStopSale(array[i]);
					}
					if (num > 0)
					{
						this.WriteErrMsg("", "批量商品下架成功！", comeUrl);
					}
				}
				else
				{
					this.WriteErrMsg("", "请选择您要下架的商品的信息", "");
				}
			}
			else
			{
				if (commandName == "MoreOnSale")
				{
					string text = Text.CheckNumList(Fetch.GetOrPost("SelectId"));
					if (text != "")
					{
						int num = 0;
						string[] array = text.Split(new char[]
						{
							','
						});
						for (int i = 0; i < array.Length; i++)
						{
							num = this.ProdcutOnSale(array[i]);
						}
						if (num > 0)
						{
							this.WriteErrMsg("", "批量商品上架成功！", comeUrl);
						}
					}
					else
					{
						this.WriteErrMsg("", "请选择您要上架的商品的信息", "");
					}
				}
				else
				{
					if (commandName == "DelInfo")
					{
						string pID = e.CommandArgument.ToString();
						int num2 = this.ProdcutDelete(pID);
						if (num2 > 0)
						{
							this.WriteErrMsg("", "删除成功！", comeUrl);
						}
					}
					else
					{
						if (commandName == "StopSale")
						{
							string pID = e.CommandArgument.ToString();
							int num3 = this.ProdcutStopSale(pID);
							if (num3 > 0)
							{
								this.WriteErrMsg("", "商品下架成功！", comeUrl);
							}
						}
						else
						{
							if (commandName == "OnSale")
							{
								string pID = e.CommandArgument.ToString();
								int num3 = this.ProdcutOnSale(pID);
								if (num3 > 0)
								{
									this.WriteErrMsg("", "商品上架成功！", comeUrl);
								}
							}
						}
					}
				}
			}
		}
		this.BindProductScore();
	}
	private int ProdcutDelete(string pID)
	{
		int result = 0;
		if (!string.IsNullOrEmpty(pID))
		{
			string sql = "update HLShop_Product set IsDeleted=1 where ProductID=" + pID;
			result = this.conn.Execute(sql);
		}
		return result;
	}
	private int ProdcutStopSale(string pID)
	{
		int result = 0;
		if (!string.IsNullOrEmpty(pID))
		{
			string sql = "update HLShop_Product Set EnableSale=0 where ProductID=" + pID;
			result = this.conn.Execute(sql);
		}
		return result;
	}
	private int ProdcutOnSale(string pID)
	{
		int result = 0;
		if (!string.IsNullOrEmpty(pID))
		{
			string sql = "update HLShop_Product Set EnableSale=1, EnableSingleSell=1,UpdateTime=getdate(),BeginDate=getdate(),EndDate=dateadd(day,ValidDay,GetDate()) where ProductID=" + pID;
			result = this.conn.Execute(sql);
		}
		return result;
	}
	protected void SeachBut_Click(object sender, EventArgs e)
	{
		this.ShowPanelDisplay(this.TabMenu);
		this.BindProductScore();
	}
	protected string GetStatus(object value)
	{
		string result = value.ToString();
		if (value.ToString().ToLower().Trim() == "true")
		{
			result = "<span style='color:Green; font-size:12px;'>√</span>";
		}
		else
		{
			if (value.ToString().ToLower().Trim() == "false")
			{
				result = "<span style='color:Red; font-size:12px;'>×</span>";
			}
		}
		return result;
	}
}
